const {Article} = require('../../model/article')
const {Comment} = require('../../model/comment')
module.exports= async(req,res)=>{
    const id = req.query.id
    // 因为要显示作者，所以需要联合查询populate('author')
    let article = await Article.findOne({_id:id}).populate('author')
    // SyntaxError: Unexpected token R in JSON at position 0   at JSON.parse (<anonymous></anonymous>
    let str1=JSON.stringify(article)
    let newArticle=JSON.parse(str1)

    let comments = await Comment.find({aid:id}).populate('uid')
    let str2=JSON.stringify(comments)
    let newComments=JSON.parse(str2)
    // res.send(comments)
    // return 
    res.render('home/article.art',{
        article:newArticle,
        comments:newComments
    })
}